package db

import (
	"github.com/gomodule/redigo/redis"
	"log"
)

func SetStringByCache(key string, data string) {
	_, err := RDS.Do("SET", key, data)
	if err != nil {
		log.Println("cache.setStringByCache SET key=", key, "data=", data, ", error=", err)
	}
}

func GetStringByCache(key string) interface{} {
	data, err := redis.String(RDS.Do("GET", key))
	if err != nil {
		log.Println("cache.getStringByCache GET key=", key, ", error=", err)
		return nil
	}
	return data
}

func HSetByCache(key string, data []interface{}) {
	if data == nil {
		return
	}
	_, err := RDS.Do("HMSET", data...)
	if err != nil {
		log.Println("cache.setStringByCache HMSET key=", key, "data=", data, ", error=", err)
	}
}

func HGetByCache(key string) interface{} {
	dataMap, err := redis.StringMap(RDS.Do("HGETALL", key))
	if err != nil {
		log.Println("user_service.getByCache HGETALL key=", key, ", error=", err)
		return nil
	}
	return dataMap
}

func DelByCache(key string) {
	_, err := RDS.Do("DEL", key)
	if err != nil {
		log.Println("cache.DelByCache DEL key=", key, ", error=", err)
	}
}
